﻿@model thailandProject.Models.Pair<List<thailandProject.Models.ERROR>, List<thailandProject.Models.USER>>

@{
    ViewBag.Title = "Error List";
}

<div id="Wrapper2">
    <div id="content_header">
        <div id="headerimage">
        </div>
        <div id="theheader">@ViewBag.Header</div>
    </div>
    <!-- Left Column begins here -->
    <aside id="sidebar-wrapper">
        <nav class="sidebar">
            <!-- CONTENT GOES HERE -->
            @using(Html.BeginForm("ErrorList", "Admin"))
            {
                int daysAgo = Session["elDaysAgo"] != null ? Convert.ToInt32(Session["elDaysAgo"].ToString()) : -1;
                string functionName = Session["elFunctionName"] != null ? Session["elFunctionName"].ToString() : "";
                int userID = Session["elUserID"] != null ? Convert.ToInt32(Session["elUserID"].ToString()) : -1;
                string errorText = Session["elErrorTextContaining"] != null ? Session["elErrorTextContaining"].ToString() : "";
                
                <div id="filter">Show filter fields...</div> 
                <div id="filterelements" style="display:none">
                    <fieldset>
                        <legend>FILTER OPTIONS</legend>
                        <div>
                            <div class="displayLabelProp">Show Errors:</div>
                            <div class="display-field">
                                <select name="daysAgo">
                                    <option value="-1" @if(daysAgo == -1) { @:selected="selected"
                                    }>All</option>
                                    <option value="30" @if(daysAgo == 30) { @:selected="selected"
                                    }>30 days ago</option>
                                    <option value="60" @if(daysAgo == 60) { @:selected="selected"
                                    }>60 days ago</option>
                                    <option value="90" @if(daysAgo == 90) { @:selected="selected"
                                    }>90 days ago</option>
                                </select>
                            </div>
                        </div>
                        <div>
                            <div class="displayLabelProp">Function Name:</div>
                            <div class="display-field">
                                <input type="text" name="functionName" value="@functionName" />
                            </div>
                         </div>
                         <div>
                            <div class="displayLabelProp">User ID:</div>
                            <div class="display-field">
                               <select name="userID">
                                    <option value="-1">All</option>
                                    @foreach (var user in Model.value2)
                                    {
                                        string text = user.userID + " - " + user.userFirstName + " " + user.userLastName;
                                        if (userID == user.userID)
                                        {
                                            <option value="@user.userID" selected="selected">@text</option>
                                        }
                                        else
                                        {
                                            <option value="@user.userID">@text</option>
                                        }
                                    }
                                </select>
                            </div>
                         </div>
                         <div>
                            <div class="displayLabelProp">Error Text Containing: </div>
                            <div class="display-field">
                                <input type="text" name="errorTextContaining" value="@errorText" />
                            </div>
                         </div>
                         <div>
                             <input type="submit" value="Filter" />
                         </div>
                     
                    </fieldset>
                </div>
            }
            <br />
            @if (Model.value1.Count != 0)
            {
                foreach (var error in Model.value1)
                {
                    <fieldset>
                        <legend>@error.errorTimeStamp</legend>
                        <strong>ErrorID  &mdash; </strong>@error.errorID
                        <br /><strong>Filename &mdash; </strong>@error.errorFileName
                        <br /><strong>Function Name &mdash; </strong>@error.errorFunctionName
                        <br /><strong>Line Number &mdash; </strong>@error.errorLineNumber
                        <br /><strong>Error Text &mdash; </strong>@error.errorText
                        <br /><strong>Error Code &mdash; </strong>@error.errorCode
                        <br /><strong>User ID &mdash; </strong>@error.userID
                        <br /><strong>Additional Error Text &mdash; </strong>@error.errorAddInfo
                        <br /><br />
                        @Html.ActionLink("Delete this error...", "ErrorDelete", new { errorID = error.errorID }, new { onclick = "return confirm('Are you sure?')" })
                    </fieldset>
                    <br />
                }
                @Html.ActionLink("Delete all errors...", "ErrorDeleteAll", null, new { onclick = "return confirm('Are you sure?')" })
                <br />
            }
            else
            {
                <p>No results found.</p>
            }

        <div>
            @Html.ActionLink("Back to Admin Home", "Index")
        </div>
        </nav>
    </aside>
    <!-- Right column begins here -->
    <article id="contents">
        <strong>Information about this error Log</strong>
        <br /><br />This displays all the error logging for this website, any error logging can be
        added by putting content in a try catch with <code>ErrorLog.logError(ex);</code> in the catch.
        <br /><code>logError</code> has a second optional string parameter for additional error text, for instance this 
        could be used to save the value(s) of problem variables.
        <br /><br /><strong>Filename</strong> - A direct path to the file generating the error
        <br /><strong>Function Name</strong> - The name of the Function with the error
        <br /><strong>Line Number</strong> - The line number where an error occured, If there is an inner exception only the outer exception line number is listed.
        <br /><strong>Error Text</strong> - The Exception text for the error.
        <br /><strong>Error Code</strong> - A unique identifier for each file, function, and error.
        <br /><strong>User ID</strong> - The user who was logged in when the error was generated, 
        if no user was logged in then this value will be -10.
        <br /><strong>Additional Error Text</strong> - This is usually blank but additional information 
        can be put in this when <code>ErrorLog.logError</code> is called.
        
    </article>
    <!-- Right column ends here -->
</div>
<!-- Div wrapper2 ends here -->

<script type="text/javascript">
    $("document").ready(function () {
        $("#filter").toggle(function () {
            $("#filterelements").css('display','');
            $("#filter").html('Hide filter fields..');
        }, function () {
            $("#filterelements").css('display', 'none');
            $("#filter").html('Show filter fields...');
        });
    })
</script>